###########################################################################
# $Id: dbTable.p 12 2009-04-15 05:13:32Z donbeave $
###########################################################################

@CLASS
dbTable

@USE
db/models/dbItem.p

@BASE
dbItem

@OPTIONS
locals

#----- Constructor -----

@create[hshOptions]
## hshOptions.name
  ^BASE:create[$hshOptions]

  ^pfAssert:isTrue(def $hshOptions.name && $hshOptions.name is string)[Option "^$.name" is not specified or wrong (CLASS_NAME: $hshOptions.name.CLASS_NAME).]

  $self._name[$hshOptions.name]

#----- Properties -----

@GET_name[]
  $result[$self._name]

@SET_name[strName]
#TODO сделать изменение названия таблицы в БД

@GET_schema[]
  $oSchemas[^MANAGER.getSchemas[]]

  ^oSchemas.foreach[oSchema]{
    ^if($oSchema.name eq $self._schemaName){
      $result[$oSchema]
    }{
       ^pfAssert:fail[Schema not specified.]
     }
  }

@GET_fields[]
  $result[^MANAGER.getTableFields[$name;$self._schemaName]]

@GET_fieldsCount[]
  $result($fields.count)

#----- Private -----

@_setSchemaName[strName]
  $self._schemaName[$strName]